package com.gy.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.gy.dao.RoomMapper;
import com.gy.domain.Userinfo;
import com.gy.service.UserinfoService;

@Controller
@RequestMapping("UserinfoHandler")
public class UserinfoHandler {
	
	@Autowired
	private UserinfoService userinfoService;
	
	
	@RequestMapping(value="insertUserinfo" ,method=RequestMethod.POST)
	@ResponseBody
	public void insertUserinfo(Userinfo userinfo, BindingResult result)
	{
		//System.out.println(name);
		
		userinfoService.insertUser(userinfo);
		//System.out.println("lala");
		//System.out.println(userinfo.toString());
	}
	
	@RequestMapping(value="selectUserinfo" ,method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
	@ResponseBody
	public String selectUserinfo(@RequestParam("uNum") String room)
	{
		//System.out.println(name);
		Userinfo user=userinfoService.selectUser(room);
		user.setuName(user.getuName());
		String userJson= JSON.toJSONString(user);
		//JSONObject jsonObj = JSONObject.parseObject(userJson);
		//String userJson1= JSON.toJSONString(jsonObj);
		System.out.println(userJson);
		
		return userJson;
		//System.out.println("lala");
		//System.out.println(userinfo.toString());
	}
	
}
